package _struct

import (
	"gitee.com/leeqiang250/go-common/util"
)

type ETHRpc struct {
	Id      string      `json:"id"`
	Method  string      `json:"method"`
	JsonRpc string      `json:"jsonrpc"`
	Params  interface{} `json:"params"`
}

func ETHRpcBlockNumber() *ETHRpc {
	return &ETHRpc{
		Id:      "1",
		Method:  "eth_blockNumber",
		JsonRpc: "2.0",
		Params:  []string{},
	}
}

type ETHResultBlockNumber struct {
	ETHResult
	ETHBlockNumber
}

func ETHRpcTransactionByHash(tx string) *ETHRpc {
	return &ETHRpc{
		Id:      "1",
		Method:  "eth_getTransactionByHash",
		JsonRpc: "2.0",
		Params:  []string{tx},
	}
}

type ETHResultTransactionByHash struct {
	ETHResult
	Result *ETHTransaction `json:"result"`
}

func ETHRpcBlockV1(number uint64, full bool) *ETHRpc {
	return ETHRpcBlockV2(util.Uint642Hex(number), full)
}

func ETHRpcBlockV2(number string, full bool) *ETHRpc {
	return &ETHRpc{
		Id:      "1",
		Method:  "eth_getBlockByNumber",
		JsonRpc: "2.0",
		Params:  []interface{}{number, full},
	}
}

type ETHResultBlock struct {
	ETHResult
	Result *ETHBlock `json:"result"`
}

func ETHRpcTransactionReceipt(txs []string) *ETHRpc {
	return &ETHRpc{
		Id:      "1",
		Method:  "eth_getTransactionReceipt",
		JsonRpc: "2.0",
		Params:  txs,
	}
}

type ETHResultTransactionReceipt struct {
	ETHResult
	Result *ETHTransactionReceipt `json:"result"`
}
